/*
 * INSANE - Interactive Structural Analysis Environment
 *
 * Copyright (C) 2003-2004
 * Universidade Federal de Minas Gerais
 * Escola de Engenharia
 * Departamento de Engenharia de Estruturas
 *
 * Author's email :     insane@dees.ufmg.br
 * Author's Website :   http://www.dees.ufmg.br/insane
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
 * 1307, USA.
 *
 */

package br.ufmg.dees.insane.ui.rich.postp.postp_view.dialog;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.WindowConstants;

import br.ufmg.dees.insane.commons.view.ViewState;
import br.ufmg.dees.insane.model.postp.PointModel;
import br.ufmg.dees.insane.model.postp.PostpModel;
import br.ufmg.dees.insane.model.postp.StepPostp;
import br.ufmg.dees.insane.ui.rich.postp.postp_controller.PostpController;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.DesktopPostp;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.InterfacePostp;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.PostpViewState;

/**
 * @author  Penna, S.S. and Pitangueira, Roque
 * @since 24/12/2006
 */
public class TensorResultsElementsDialog extends JFrame {
	
	/**   */
	private static final long serialVersionUID = 1L;
	
	private DesktopPostp desktop;
	private InterfacePostp intFrame;
	private PostpModel postpModel;
	private PostpViewState state;
	
	//	 Variables declaration - do not modify
	private JButton copyButton1;
	private JButton copyButton2;
	private JButton copyButton3;
	private JButton addButton;
	private JButton resetButton;
	private JButton viewButton;
	private JButton closeButton;
	private JList keyListPanel;
	private JList tensorList;
	private JPanel tensorPanel;
	private JPanel labelPanel;
	private JPanel tensorListPanel;
	private JScrollPane keyListScrollPane;
	private JScrollPane tensorListScrollPane;
	private JTextField copyTextField1;
	private JTextField copyTextField2;
	private JTextField copyTextField3;
	private JTextField tensorXXTextField;
	private JTextField tensorYXTextField;
	private JTextField tensorYYTextField;
	private JTextField tensorXYTextField;
	private JTextField value1TextField;
	private JTextField value2TextField;
	private JTextField value3TextField;
	private JCheckBox openInANewWindowCheckBox;
	private JCheckBox onGaussCheckBox ;
	private JCheckBox onFullMeshCheckBox;
	private JCheckBox onMeshCheckBox;
	// End of variables declaration
	
	private String[] keysValues;
	private Vector<String> tensorDataValues;
	
	private TensorResultsElementsDialog thisDlg;
	
	/** Creates new form NewJFrame */
	public TensorResultsElementsDialog(DesktopPostp desktop, ViewState vs, String[] keys) {
		this.desktop = desktop;
		this.intFrame = (InterfacePostp)((DesktopPostp)this.desktop).getDesktop().getSelectedFrame();
		this.state = (PostpViewState)vs;
		this.keysValues = new String[keys.length+1];
		for (int i = 0; i < this.keysValues.length-1; i++) {
			this.keysValues[i] = keys[i];
		}
		this.keysValues[keysValues.length-1] = ""; 
		tensorDataValues = new Vector<String>();
		initComponents();
	}
	
	/** Creates new form NewJFrame */
	public TensorResultsElementsDialog() {
		initComponents();
	}
	
	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
	private void initComponents() {
		thisDlg = this;
		this.setTitle("Tensor Result"+" - "+this.intFrame.getPostpModel().getLabel());
		Image ico = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Insane64.gif"));
		this.setIconImage(ico);
		this.setSize(new Dimension(675,420));
		this.setMaximumSize(new Dimension(675,420));
		this.setMinimumSize(new Dimension(675,420));
		this.setPreferredSize(new Dimension(675,420));
		this.setResizable(false);
		this.setAlwaysOnTop(true);
		this.setLocationRelativeTo(this.desktop);
		
		keyListScrollPane = new JScrollPane();
		tensorListScrollPane = new JScrollPane();
		keyListPanel = new JList();
		tensorList = new JList();
		copyTextField1 = new JTextField();
		copyTextField2 = new JTextField();
		copyTextField3 = new JTextField();
		copyButton1 = new JButton();
		copyButton2 = new JButton();
		copyButton3 = new JButton();
		tensorPanel = new JPanel();
		tensorXXTextField = new JTextField();
		tensorXYTextField = new JTextField();
		tensorYXTextField = new JTextField();
		tensorYYTextField = new JTextField();
		value1TextField = new JTextField();
		value2TextField = new JTextField();
		value3TextField = new JTextField();
		labelPanel = new JPanel();
		tensorPanel = new JPanel();    
		tensorListPanel = new JPanel();
		addButton = new JButton();
		resetButton = new JButton();
		viewButton = new JButton();
		closeButton = new JButton();
		openInANewWindowCheckBox = new JCheckBox();
		onGaussCheckBox = new JCheckBox();
		onFullMeshCheckBox = new JCheckBox();
		onMeshCheckBox = new JCheckBox();
		
		getContentPane().setLayout(null);
		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		
		//Setting the key list scrollPanel
		keyListScrollPane.setBorder(BorderFactory.createTitledBorder(""));
		keyListPanel.setBackground(new Color(0, 0, 5));
		keyListPanel.setFont(new Font("Arial", Font.PLAIN,12));
		keyListPanel.setForeground(new Color(0, 255, 0));
		keyListPanel.setListData(keysValues);
		keyListPanel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		keyListPanel.setSelectionBackground(new Color(153, 204, 255));
		keyListPanel.setSelectionForeground(new Color(0, 0, 0));
		keyListPanel.setVisibleRowCount(50);
		keyListPanel.setFixedCellHeight(20);
		keyListScrollPane.setViewportView(keyListPanel);
		
		getContentPane().add(keyListScrollPane);
		keyListScrollPane.setBounds(10, 10, 200, 300);
		
		//Setting the copy buttons and the copy fields
		copyTextField1.setBackground(new Color(0, 0, 0));
		copyTextField1.setEditable(false);
		copyTextField1.setForeground(new Color(0, 255, 0));
		copyTextField1.setHorizontalAlignment(JTextField.CENTER);
		copyTextField1.setText("");
		getContentPane().add(copyTextField1);
		copyTextField1.setBounds(325, 20, 105, 30);
		
		copyTextField2.setBackground(new Color(0, 0, 0));
		copyTextField2.setEditable(false);
		copyTextField2.setForeground(new Color(0, 255, 0));
		copyTextField2.setHorizontalAlignment(JTextField.CENTER);
		copyTextField2.setText("");
		getContentPane().add(copyTextField2);
		copyTextField2.setBounds(325, 60, 105, 30);
		
		copyTextField3.setBackground(new Color(0, 0, 0));
		copyTextField3.setEditable(false);
		copyTextField3.setForeground(new Color(0, 255, 0));
		copyTextField3.setHorizontalAlignment(JTextField.CENTER);
		copyTextField3.setText("");
		getContentPane().add(copyTextField3);
		copyTextField3.setBounds(325, 100, 105, 30);
		
		copyButton1.setText(" T11 ");
		getContentPane().add(copyButton1);
		copyButton1.setToolTipText("Copy value T11 to Tensor");
		copyButton1.setBounds(220, 23, 96, 23);
		copyButton1.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						copyTextField1.setText(addText(keyListPanel));
						tensorXXTextField.setText(addText(keyListPanel));
					}
				});
		
		copyButton2.setText(" T22 ");
		getContentPane().add(copyButton2);
		copyButton2.setToolTipText("Copy value T22 to Tensor");
		copyButton2.setBounds(220, 63, 96, 23);
		copyButton2.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						copyTextField2.setText(addText(keyListPanel));
						tensorYYTextField.setText(addText(keyListPanel));
					}
				});
		
		copyButton3.setText(" T12/T21 ");
		getContentPane().add(copyButton3);
		copyButton3.setToolTipText("Copy value T12 and T21 to Tensor");
		copyButton3.setBounds(220, 103, 96, 23);
		copyButton3.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						copyTextField3.setText(addText(keyListPanel));
						tensorXYTextField.setText(addText(keyListPanel));
						tensorYXTextField.setText(addText(keyListPanel));
					}
				});
		
		//Setting the tensor panel
		tensorPanel.setLayout(new GridLayout(2, 2));
		
		tensorPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Tensor"));
		tensorXXTextField.setBackground(new Color(0, 0, 0));
		tensorXXTextField.setEditable(false);
		tensorXXTextField.setFont(new Font("Arial", Font.PLAIN,12));
		tensorXXTextField.setForeground(new Color(0, 255, 0));
		tensorXXTextField.setHorizontalAlignment(JTextField.CENTER);
		tensorXXTextField.setText("");
		tensorPanel.add(tensorXXTextField);
		
		tensorXYTextField.setBackground(new Color(0, 0, 0));
		tensorXYTextField.setEditable(false);
		tensorXYTextField.setFont(new Font("Arial", Font.PLAIN,12));
		tensorXYTextField.setForeground(new Color(0, 255, 0));
		tensorXYTextField.setHorizontalAlignment(JTextField.CENTER);
		tensorXYTextField.setText("");
		tensorPanel.add(tensorXYTextField);
		
		tensorYXTextField.setBackground(new Color(0, 0, 0));
		tensorYXTextField.setEditable(false);
		tensorYXTextField.setFont(new Font("Arial", Font.PLAIN,12));
		tensorYXTextField.setForeground(new Color(0, 255, 0));
		tensorYXTextField.setHorizontalAlignment(JTextField.CENTER);
		tensorYXTextField.setText("");
		tensorPanel.add(tensorYXTextField);
		
		tensorYYTextField.setBackground(new Color(0, 0, 0));
		tensorYYTextField.setEditable(false);
		tensorYYTextField.setFont(new Font("Arial", Font.PLAIN,12));
		tensorYYTextField.setForeground(new Color(0, 255, 0));
		tensorYYTextField.setHorizontalAlignment(JTextField.CENTER);
		tensorYYTextField.setText("");
		tensorPanel.add(tensorYYTextField);
		
		getContentPane().add(tensorPanel);
		tensorPanel.setBounds(440, 10, 220, 120);
		
		//Setting the label panel:    
		labelPanel.setLayout(null);
		labelPanel.setBorder(BorderFactory.createTitledBorder("Labels"));
		
		JLabel value1Label = new JLabel();
		value1Label.setFont(new Font("Arial", Font.PLAIN,12));
		value1Label.setText("T11:");
		labelPanel.add(value1Label);
		value1Label.setBounds(10, 30, 60, 30);
		
		value1TextField.setBackground(new Color(0, 0, 0));
		value1TextField.setForeground(new Color(0, 255, 0));
		value1TextField.setCaretColor(new Color(0, 255, 0));
		value1TextField.setText("");
		labelPanel.add(value1TextField);
		value1TextField.setBounds(70, 30, 130, 30);
		
		JLabel value2Label = new JLabel();
		value2Label.setFont(new Font("Arial", Font.PLAIN,12));
		value2Label.setText("T22:");
		labelPanel.add(value2Label);
		value2Label.setBounds(10, 80, 60, 30);
		
		value2TextField.setBackground(new Color(0, 0, 0));
		value2TextField.setForeground(new Color(0, 255, 0));
		value2TextField.setCaretColor(new Color(0, 255, 0));
		value2TextField.setText("");
		labelPanel.add(value2TextField);
		value2TextField.setBounds(70, 80, 130, 30);
		
		JLabel value3Label = new JLabel();
		value3Label.setFont(new Font("Arial", Font.PLAIN,12));
		value3Label.setText("T12/T21:");
		labelPanel.add(value3Label);
		value3Label.setBounds(10, 130, 60, 30);
		
		value3TextField.setBackground(new Color(0, 0, 0));
		value3TextField.setForeground(new Color(0, 255, 0));
		value3TextField.setCaretColor(new Color(0, 255, 0));
		value3TextField.setText("");
		labelPanel.add(value3TextField);
		value3TextField.setBounds(70, 130, 130, 30);
		
		getContentPane().add(labelPanel);
		labelPanel.setBounds(220, 140, 210, 170);
		
		//tensor computed panellist
		tensorListPanel.setLayout(null);
		
		tensorListPanel.setBorder(BorderFactory.createTitledBorder(""));
		tensorList.setBackground(new Color(0, 0, 0));
		tensorList.setForeground(new Color(0, 255, 0));
		tensorList.setFont(new Font("Arial", Font.PLAIN,12));
		tensorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		tensorList.setSelectionBackground(new Color(153, 204, 255));
		tensorList.setSelectionForeground(new Color(0, 0, 0));
		tensorListScrollPane.setViewportView(tensorList);
		
		tensorListPanel.add(tensorListScrollPane);
		tensorListScrollPane.setBounds(10, 10, 110, 150);
		
		getContentPane().add(tensorListPanel);
		tensorListPanel.setBounds(530, 140, 130, 170);
		
		//Setting the buttons
		addButton.setText("Add");
		getContentPane().add(addButton);
		addButton.setBounds(440, 150, 80, 23);
		addButton.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						if(!tensorXXTextField.getText().equals("")
								||!tensorYYTextField.getText().equals("")
								||!tensorXYTextField.getText().equals("")){
							addValues();
						}else{
							String message = "You must fill the values!"; 
							JOptionPane.showMessageDialog(thisDlg, message, "Warning", JOptionPane.INFORMATION_MESSAGE);
						}
					}
				});
		
		resetButton.setText("Reset");
		getContentPane().add(resetButton);
		resetButton.setBounds(440, 210, 80, 23);
		resetButton.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						value1TextField.setText("");
						value2TextField.setText("");
						value3TextField.setText("");
						copyTextField1.setText("");
						copyTextField2.setText("");
						copyTextField3.setText("");
						tensorXXTextField.setText("");
						tensorYYTextField.setText("");
						tensorXYTextField.setText("");
						tensorYXTextField.setText("");
					}
				});
		
		viewButton.setText("View");
		getContentPane().add(viewButton);
		viewButton.setBounds(440, 270, 80, 23);
		viewButton.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						if(tensorList.getSelectedValue()!=null){
							view(event);
						}else{
							String message = "Select a value!"; 
							JOptionPane.showMessageDialog(thisDlg, message, "Warning", JOptionPane.INFORMATION_MESSAGE);
						}
						
					}
				});
		
		closeButton.setText("Close");
		getContentPane().add(closeButton);
		closeButton.setBounds(540, 350, 100, 23);
		closeButton.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						close(event);
					}
				});
		
		
		openInANewWindowCheckBox.setText("Open in a new Window");
		openInANewWindowCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
		openInANewWindowCheckBox.setMargin(new Insets(0, 0, 0, 0));
		getContentPane().add(openInANewWindowCheckBox);
		openInANewWindowCheckBox.setBounds(290, 350, 150, 23);
		
		onGaussCheckBox = new JCheckBox("From Gauss values");
		onGaussCheckBox.setSelected(true);
		ActionListener onGaussListener = new ChoiceListenerOnGaussMesh();       
		onGaussCheckBox.addActionListener(onGaussListener);
		getContentPane().add(onGaussCheckBox);
		onGaussCheckBox.setBounds(20,315, 200, 20);
		
		onFullMeshCheckBox = new JCheckBox("From Gauss and nodal values");
		onFullMeshCheckBox.setSelected(false);
		ActionListener onFullMeshListener = new ChoiceListenerOnFullMesh();       
		onFullMeshCheckBox.addActionListener(onFullMeshListener);
		getContentPane().add(onFullMeshCheckBox);
		onFullMeshCheckBox.setBounds(20, 340, 200, 20);
		
		onMeshCheckBox = new JCheckBox("From nodal values");
		onMeshCheckBox.setSelected(false);
		ActionListener onMeshListener = new ChoiceListenerOnMesh();       
		onMeshCheckBox.addActionListener(onMeshListener);
		getContentPane().add(onMeshCheckBox);
		onMeshCheckBox.setBounds(20, 365, 200, 20);
		
	}// </editor-fold>
	
	public void close(ActionEvent event){
		this.dispose();
	}
	
	private void addValues(){
		PostpModel postp = ((InterfacePostp)this.intFrame).getPostpModel();
		for(int i=0;i<postp.getStepList().size();i++){
			StepPostp step = postp.getStepList().get(i);
			ArrayList<PointModel> points = step.getGeoPostpModelList().get(0).getPoints();
			for(int j=0;j<points.size();j++){
				PointModel point  = points.get(j);
				double s1 = (Double)point.getValue(tensorXXTextField.getText());
				double s2 = (Double)point.getValue(tensorYYTextField.getText());
				double s3 = (Double)point.getValue(tensorXYTextField.getText());
				double v1 = ((s1+s2)/2)+Math.sqrt( Math.pow(((s1-s2)/2),2)+ Math.pow(s3,2));
				double v2 = ((s1+s2)/2)-Math.sqrt( Math.pow(((s1-s2)/2),2)+ Math.pow(s3,2));
				double v3 = Math.sqrt( Math.pow(((s1-s2)/2),2)+ Math.pow(s3,2));
				if(value1TextField.getText().equals("")){
					point.putValue("Eigenvalue-1",v1);
					if(!tensorDataValues.contains("Eigenvalue-1")){
						tensorDataValues.add("Eigenvalue-1");
					}
				}else{
					point.putValue(value1TextField.getText(),v1);
					if(!tensorDataValues.contains(value1TextField.getText())){
						tensorDataValues.add(value1TextField.getText());
					}
				}
				
				if(value2TextField.getText().equals("")){
					point.putValue("Eigenvalue-2",v2);
					if(!tensorDataValues.contains("Eigenvalue-2")){
						tensorDataValues.add("Eigenvalue-2");
					}
				}else{
					point.putValue(value2TextField.getText(),v2);
					if(!tensorDataValues.contains(value2TextField.getText())){
						tensorDataValues.add(value2TextField.getText());
					}
				}
				
				if(value3TextField.getText().equals("")){
					point.putValue("Eigenvalue-12,21",v3);
					if(!tensorDataValues.contains("Eigenvalue-12,21")){
						tensorDataValues.add("Eigenvalue-12,21");
					}
				}else{
					point.putValue(value3TextField.getText(),v3);
					if(!tensorDataValues.contains(value3TextField.getText())){
						tensorDataValues.add(value3TextField.getText());
					}
				}
				
			}
			
			points = step.getGeoPostpModelList().get(1).getPoints();
			for(int j=0;j<points.size();j++){
				PointModel point  = points.get(j);
				double s1 = (Double)point.getValue(tensorXXTextField.getText());
				double s2 = (Double)point.getValue(tensorYYTextField.getText());
				double s3 = (Double)point.getValue(tensorXYTextField.getText());
				double v1 = ((s1+s2)/2)+Math.sqrt( Math.pow(((s1-s2)/2),2)+ Math.pow(s3,2));
				double v2 = ((s1+s2)/2)-Math.sqrt( Math.pow(((s1-s2)/2),2)+ Math.pow(s3,2));
				double v3 = Math.sqrt( Math.pow(((s1-s2)/2),2)+ Math.pow(s3,2));
				if(value1TextField.getText().equals("")){
					point.putValue("Eigenvalue-1",v1);
					if(!tensorDataValues.contains("Eigenvalue-1")){
						tensorDataValues.add("Eigenvalue-1");
					}
				}else{
					point.putValue(value1TextField.getText(),v1);
					if(!tensorDataValues.contains(value1TextField.getText())){
						tensorDataValues.add(value1TextField.getText());
					}
				}
				
				if(value2TextField.getText().equals("")){
					point.putValue("Eigenvalue-2",v2);
					if(!tensorDataValues.contains("Eigenvalue-2")){
						tensorDataValues.add("Eigenvalue-2");
					}
				}else{
					point.putValue(value2TextField.getText(),v2);
					if(!tensorDataValues.contains(value2TextField.getText())){
						tensorDataValues.add(value2TextField.getText());
					}
				}
				
				if(value3TextField.getText().equals("")){
					point.putValue("Eigenvalue-12,21",v3);
					if(!tensorDataValues.contains("Eigenvalue-12,21")){
						tensorDataValues.add("Eigenvalue-12,21");
					}
				}else{
					point.putValue(value3TextField.getText(),v3);
					if(!tensorDataValues.contains(value3TextField.getText())){
						tensorDataValues.add(value3TextField.getText());
					}
				}
				
			}
		}
		this.tensorList.setListData(tensorDataValues);
		this.postpModel = postp;
		this.intFrame.setPostpModel(this.postpModel);
		this.intFrame.setStep(this.postpModel.getStepList().get(0));
	}
	
	public void view(ActionEvent event){
		this.state.setDeformedOn(true);
		if(this.openInANewWindowCheckBox.isSelected()){
			InterfacePostp intFrame = new InterfacePostp();
			intFrame.validate();
			intFrame.setPostpModel(this.postpModel);
			intFrame.setModel(this.postpModel.getStepList().get(0));
			intFrame.setTitle(this.postpModel.getLabel());
			((DesktopPostp)this.desktop).addInternalFrame(intFrame);
			intFrame.toFront();
			this.state = (PostpViewState)((InterfacePostp)intFrame).getView().getViewState();
			this.state.getEdgeViewState().setLineColor(Color.WHITE);
			this.state.getNodalsPlotContoursViewState().setContourOnOff(false);
			this.state.getElementsPlotContoursViewState().setContourOnOff(true);
			this.state.getElementsPlotContoursViewState().setDiscontinuosContourOnOff(false);
			this.state.getElementsPlotContoursViewState().setElementsContoursComputed(true);
			this.state.getElementsPlotContoursViewState().setKeyValue((String)this.tensorList.getSelectedValue());
			if(onGaussCheckBox.isSelected()){
				this.state.getElementsPlotContoursViewState().setTriangulateWithNodesOnOff(false);
				this.state.getElementsPlotContoursViewState().setOnMesh(false);
			}
			if(onFullMeshCheckBox.isSelected()){
				this.state.getElementsPlotContoursViewState().setTriangulateWithNodesOnOff(true);
				this.state.getElementsPlotContoursViewState().setOnMesh(false);
			}
			if(onMeshCheckBox.isSelected()){
				this.state.getElementsPlotContoursViewState().setTriangulateWithNodesOnOff(false);
				this.state.getElementsPlotContoursViewState().setOnMesh(true);
			}
			this.state.getScaleColorsViewState().setScaleContoursOnOff(true);
			((PostpController)((InterfacePostp)this.intFrame).getView().getController()).width = 2; 
			(intFrame).getView().getDrawingArea().repaint();    
		}else{
			this.state = (PostpViewState)((InterfacePostp)intFrame).getView().getViewState();
			this.state.getEdgeViewState().setLineColor(Color.WHITE);
			this.state.getNodalsPlotContoursViewState().setContourOnOff(false);
			this.state.getElementsPlotContoursViewState().setContourOnOff(true);
			this.state.getElementsPlotContoursViewState().setDiscontinuosContourOnOff(false);
			this.state.getElementsPlotContoursViewState().setElementsContoursComputed(true);
			this.state.getElementsPlotContoursViewState().setKeyValue((String)this.tensorList.getSelectedValue());
			if(onGaussCheckBox.isSelected()){
				this.state.getElementsPlotContoursViewState().setTriangulateWithNodesOnOff(false);
				this.state.getElementsPlotContoursViewState().setOnMesh(false);
			}
			if(onFullMeshCheckBox.isSelected()){
				this.state.getElementsPlotContoursViewState().setTriangulateWithNodesOnOff(true);
				this.state.getElementsPlotContoursViewState().setOnMesh(false);
			}
			if(onMeshCheckBox.isSelected()){
				this.state.getElementsPlotContoursViewState().setTriangulateWithNodesOnOff(false);
				this.state.getElementsPlotContoursViewState().setOnMesh(true);
			}
			this.state.getScaleColorsViewState().setScaleContoursOnOff(true);
			((PostpController)((InterfacePostp)this.intFrame).getView().getController()).width = 2; 
			((InterfacePostp)((DesktopPostp)this.desktop).getDesktop().getSelectedFrame()).getView().getDrawingArea().repaint();
		}
	}
	
	private class ChoiceListenerOnGaussMesh implements ActionListener{
		public void actionPerformed(ActionEvent event){
			onGaussCheckBox.setSelected(true);
			onFullMeshCheckBox.setSelected(false);
			onMeshCheckBox.setSelected(false);
		}    
	}
	
	private class ChoiceListenerOnFullMesh implements ActionListener{
		public void actionPerformed(ActionEvent event){
			onGaussCheckBox.setSelected(false);
			onFullMeshCheckBox.setSelected(true);
			onMeshCheckBox.setSelected(false);
		}    
	}
	
	private class ChoiceListenerOnMesh implements ActionListener{
		public void actionPerformed(ActionEvent event){
			onGaussCheckBox.setSelected(false);
			onFullMeshCheckBox.setSelected(false);
			onMeshCheckBox.setSelected(true);
		}    
	}
	
	private String addText(JList list){
		String text="";
		for(int i=0;i<list.getSelectedValues().length;i++){
			text+=((String)list.getSelectedValues()[i]);
		}
		return text;
	}
	
	public String[] getKeysValues() {
		return keysValues;
	}
	
	public void setKeysValues(String[] keysValues) {
		this.keysValues = keysValues;
	}
	
//	***********************************************************************************************   
}//end of this class
